import QtQuick
import QtQuick.Controls
import QtQuick.Window 2.3
import QtQuick.Layouts  1.3

Window {
    id:main
    width: 640
    height: 480
    visible: true
    title: qsTr("Hello zzs")
    flags: Qt.Window | Qt.FramelessWindowHint
    color: Qt.rgba(0,0,0,0)
    property int dragX: 0
    property int dragY: 0
    property bool dragging: false
    // color: "black"
    Image {
        id: backGroud
        anchors.fill: parent
        source: "icons/back.png"
    }

    ResizableRectangle{
        anchors.fill: parent
        resizeTarget: main
    }

    //导航栏start--------------------------------------
    //测试 默认在左侧
    Rectangle
    {
        id : rootitem
        x:0
        y:30
        anchors.left: parent.left
        //anchors.leftMargin: 0
        width: 100;
        height: parent.height;
        color: Qt.rgba(0,0,0,0)

        ColumnLayout{
            id : lyout
            width: parent.width
            //height: parent.height
            Layout.fillWidth: true
            spacing: 30
        }
    }
    //导航栏end----------------------------------------

    //添加项
    function addItem(text,index)
    {
        var component = Qt.createComponent("SideBar.qml");
        if (component.status === Component.Ready)
        {
            var itemrect = component.createObject(lyout);
            itemrect.text = text;
            itemrect.index = index;
            itemrect.mclicked.connect(mmclicked); //信号的关联槽函数
        }
    }
    Component.onCompleted:
    {
        addItem("数据分析",0)
        addItem("测试2",1)
        addItem("测试3",2)
    }


    SwipeView {
        id: swipeView
        anchors.left: rootitem.right
        anchors.top: parent.top
        anchors.right: parent.right
        anchors.bottom: parent.bottom
        currentIndex: 0
        Rectangle{
            color: Qt.rgba(0,0,0,0)
            //anchors.fill: parent
        }
        Rectangle{
            color: Qt.rgba(0,0,0,0)
            //anchors.fill: parent
        }
        Rectangle{
            color: Qt.rgba(0,0,0,0)
            //anchors.fill: parent
        }
    }

    //事件处理
    function mmclicked(index)
    {
        swipeView.currentIndex = index;
        for (var i in lyout.children)
        {
            if (lyout.children[i].index !== index)
                lyout.children[i].clearColor();
        }
    }

    // 主页面一开始设置"隐藏"，登录成功后才显示
    Border{
        id:boder
        width: main.width
        height: 30
        // anchors.top: parent
    }

    Analyiz {
        id: analyiz
        x:150
        y:30
        visible: false // 设置"隐藏"
        //anchors.centerIn: parent
    }

    LoginPage {
        id: loginPage
        x:150
        y:30
        width: 490
        height: 450
        visible: false // 设置"隐藏"
        // anchors.centerIn: parent
    }
}

